package cn.com.joco.dk.webby.action.user;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
@RequestMapping(value = "/login")
public class LoginAction {
	private static Logger logger = LoggerFactory.getLogger(LoginAction.class);  
	@RequestMapping(method = RequestMethod.GET)
	public String login(HttpServletResponse response) {
		 response.setDateHeader("Expires", -1);//IE
	        response.setHeader("Cache-Control", "no-cache");
	        response.setHeader("Pragma", "no-cache");
		SecurityUtils.getSubject().logout();
		response.addCookie(new Cookie("module", "webby"));
		
		return "user/login";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName, Model model) {
		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName);
		return "user/login";
	}
}
